package read.xml;


import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.*;
 
public class ReadXMLFile {
 
  public static void main(String argv[]) {
 
    try {
 
	File fXmlFile = new File("C:\\Users\\TIEN NGUYEN\\Desktop\\testxml.xml");
	DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
	DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
	Document doc = dBuilder.parse(fXmlFile);
 
	
	doc.getDocumentElement().normalize();
 
	System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
 
	NodeList nList = doc.getElementsByTagName("stt");
 
	System.out.println("----------------------------");
 
	for (int temp = 0; temp < nList.getLength(); temp++) {
 
		Node nNode = nList.item(temp);
 
		System.out.println("\nCurrent Element :" + nNode.getNodeName());
 
		if (nNode.getNodeType() == Node.ELEMENT_NODE) {
 
			Element eElement = (Element) nNode;
 
			System.out.println("STT : " + eElement.getAttribute("id"));
			System.out.println("MSSV : " + eElement.getElementsByTagName("mssv").item(0).getTextContent());
			System.out.println("Ho ten : " + eElement.getElementsByTagName("hoten").item(0).getTextContent());
			System.out.println("Ngay sinh : " + eElement.getElementsByTagName("ngaysinh").item(0).getTextContent());
			System.out.println("Dia chi : " + eElement.getElementsByTagName("diachi").item(0).getTextContent());
			System.out.println("Dien thoai : " + eElement.getElementsByTagName("phone").item(0).getTextContent());
			System.out.println("Email : " + eElement.getElementsByTagName("email").item(0).getTextContent());
 
		}
	}
    } catch (Exception e) {
	e.printStackTrace();
    }
  }
 
}